package com.kuyun.parseexcel.parsemodule.strategyInterface.strategyImpl;

import com.kuyun.parseexcel.parsemodule.bean.JHACSExcel;
import com.kuyun.parseexcel.parsemodule.bean.TemplateBean;
import com.kuyun.parseexcel.parsemodule.instance.OutOrIn;
import com.kuyun.parseexcel.parsemodule.instance.PlateColor;
import com.kuyun.parseexcel.parsemodule.strategyInterface.AbstractExcelDataHandle;
import org.apache.commons.codec.digest.DigestUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

public class JhacsExcelDataHandle extends AbstractExcelDataHandle<JHACSExcel> {

    private Map<String, String> map = new HashMap<>();

    public JhacsExcelDataHandle(String file) {
        super(file, JHACSExcel.class);
    }

    @Override
    public void shareData() {
        boolean isout = this.getData().getPlace().contains("出口");
        if (isout) {
            map.put("outOrIn", OutOrIn.OUT);
        } else {
            map.put("outOrIn", OutOrIn.IN);
        }

        if (OutOrIn.OUT.equals(map.get(TemplateBean.Fields.outOrIn))) {
            map.put(TemplateBean.Fields.deviceName, "离场通道");
        } else {
            map.put(TemplateBean.Fields.deviceName, "进场通道");
        }

    }
    @Override
    public String handleParkingNo() {
        return "100019";
    }

    @Override
    public String handleAuthType() {
        return "车牌号码";
    }

    @Override
    public String handleAuthNo() {
        return this.getData().getRenameCarNumber().trim();
    }

    @Override
    public String handleDeviceNo() {
        return DigestUtils.md5Hex(map.get(TemplateBean.Fields.deviceName));
    }

    @Override
    public String handleDeviceName() {
        return map.get(TemplateBean.Fields.deviceName);
    }

    @Override
    public String handleEntryNo() {
        return DigestUtils.md5Hex(map.get(TemplateBean.Fields.deviceName));
    }

    @Override
    public String handleEntryName() {
        return map.get(TemplateBean.Fields.deviceName);
    }

    @Override
    public String handleCarPlateColor() {
        String plateColor = PlateColor.BLUE;
        String carColor = getData().getCarPlateColor();
        if (carColor != null) {
            if (carColor.contains("绿")){
                plateColor = PlateColor.GREEN;
            } else if (carColor.contains("黄")) {
                plateColor = PlateColor.YELLO;
            } else if (carColor.contains("白")) {
                plateColor = PlateColor.WHITE;
            } else if (carColor.contains("黑")) {
                plateColor = PlateColor.BLACK;
            } else if (carColor.contains("蓝")) {
                plateColor = PlateColor.BLUE;
            }
        }
        return plateColor;
    }

    @Override
    public String handleCarType() {
        return "小型车";
    }

    @Override
    public String handleParkingType() {
        return "临时车";
    }

    @Override
    public String handleLicensePlate() {
        return getData().getRenameCarNumber().trim();
    }

    @Override
    public String handleOutOrIn() {
        return map.get(TemplateBean.Fields.outOrIn);
    }

    @Override
    public String handleTrafficTime() {
        String tarfficTime = null;
        DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        DateFormat target = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String parkingType = null;
        try {
            tarfficTime = target.format(format.parse(getData().getTrafficTime()));
        } catch (ParseException e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
        return tarfficTime;
    }

    @Override
    public String handleTrafficType() {
        return "正常进出";
    }

    @Override
    public String handleHasCapture() {
        return "否";
    }

    @Override
    public String handleOther() {
        return null;
    }

    @Override
    public String handleAppCode() {
        return "8c72912ce8204b7da1d7c47f796f2907";
    }

    @Override
    public boolean invalidDataCondition() {
        if (getData().getRenameCarNumber() == null) {
            return true;
        }
        return false;
    }


}
